package danny.hoi.web.controller.stat;

import com.alibaba.dubbo.config.annotation.Reference;
import danny.hoi.service.export.stat.StatService;
import danny.hoi.web.controller.base.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/stat")
public class StatController extends BaseController {
    @Reference
    private StatService statService;

    /**
     * 访问统计分析页面
     * /stat/toCharts.do?chartsType=factory
     */
    @RequestMapping("/toCharts")
    public String toCharts(String chartsType) {
        return "stat/stat-" + chartsType;
    }

    /**
     * 获取生产厂家销售统计
     * name 工厂名字
     * value 销售金额
     */
    @RequestMapping("/factoryCharts")
    @ResponseBody
    public List<Map<String, Object>> getFactoryData() {
        return statService.getFactoryData(getLoginCompanyId());
    }

    /**
     * 获取商品销售排行前5
     * name product_no
     * value 销售数量
     */
    @RequestMapping("/sellCharts")
    @ResponseBody
    public List<Map<String, Object>> getSellData() {
        return statService.getSellData(getLoginCompanyId(), 5);
    }

    /**
     * 获取每小时访问人数统计
     */
    @RequestMapping("/onlineCharts")
    @ResponseBody
    public List<Map<String, Object>> getOnlineData() {
        return statService.getOnlineData(getLoginCompanyId());
    }

}
